﻿// --------------------------------
// <copyright file="AMenuItem.cs" company="Faculty of Information Technology, Czech Technical University in Prague">
//     This document is shared by Microsoft Public License (MS-PL)
//     For further details please see http://msdn.microsoft.com/en-us/library/ff648068.aspx or license.txt.
// </copyright>
// <author>Lukáš Molnár</author>

// <email>molnaluk@fit.cvut.cz</email>

// <date>14. 2. 2012 0:13:46</date>

// <summary>
// 
// </summary>
// --------------------------------

using System.Xml.Serialization;

#if WINDOWS

using System.ComponentModel;

#endif

using Microsoft.Xna.Framework;

namespace FITClub.TextureMenu
{
#if WINDOWS

    [System.Serializable]
#endif
    /// <summary>
    /// Base class for active menu item.
    /// </summary>
    public abstract class AMenuItem : ADisplayable
    {
        /// <summary>
        /// True if element is focusable.
        /// Default: true
        /// </summary>
        [XmlAttribute]
        public bool IsEnabled { get; set; }

        /// <summary>
        /// Should be menu specific action sound played when this item is hit?
        /// </summary>
        [XmlAttribute]
        public bool PlayPushedSound { get; set; }

        /// <summary>
        /// Action descriptor
        /// </summary>
#if WINDOWS

        [TypeConverter(typeof(ExpandableObjectConverter))]
#endif
        [XmlElement]
        public MenuItemAction Action { get; set; }

        /// <summary>
        /// True if element is focused and can perform action.
        /// </summary>
        [XmlIgnore]
        public bool IsSelected { get; set; }

        public AMenuItem()
        {
            IsEnabled = true;
            PlayPushedSound = true;
        }

        /// <summary>
        /// Draw selection background if selected.
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="tint"></param>
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Color tint)
        {
            if (this.IsSelected)
            {
                //spriteBatch.Draw(Owner.SelectionTexture, this.Bounds, Owner.SelectedItemBackground);
                MenuHelper.FillRectangle(spriteBatch, this.Bounds, this.Owner.SelectedItemBackground);
            }
        }

        /// <summary>
        /// Item lost focus.
        /// </summary>
        public virtual void ItemLeft()
        {
        }

        /// <summary>
        /// Item got focus.
        /// </summary>
        public virtual void ItemSelected()
        {
        }
    }
}